﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Utils;
//考勤数据
//来自于考勤软件数据库
namespace UI.ModSalary
{
    public partial class AttendanceList : System.Web.UI.Page
    {
        DefDicBiz defDicBiz = new DefDicBiz();
     //   SalaryTableBiz salaryTableBiz = new SalaryTableBiz();
        FromKingdeeBiz fromKingdeeBiz = new FromKingdeeBiz();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RegexRule.CheckLoginUser();
                defDicBiz.InitXMLDropDownList(ddlYear, "YearList.xml", System.DateTime.Now.Year.ToString());
                defDicBiz.InitXMLDropDownList(ddlMonth, "MonthList.xml", (System.DateTime.Now.Month - 1).ToString());
              
            }
        }

        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            string empCode = txtSeWord.Text.Trim();//只查询使用
            string strYear = ddlYear.SelectedItem.Text;
            string strMonth = ddlMonth.SelectedItem.Text;
            DataTable dt = fromKingdeeBiz.GetLists(empCode, strYear, strMonth);
            int r = dt.Rows.Count;
            if (r > 0)
            {
                gvList.DataSource = dt;
                gvList.DataBind();
                lbAmount.Text = "总人数：" + r.ToString();
            }
            
        }
        //从考勤软件里面提取数据
        protected void btnGetKq_Click(object sender, EventArgs e)
        {
            string strYear = ddlYear.SelectedItem.Text;
            string strMonth = ddlMonth.SelectedItem.Text;

            if (fromKingdeeBiz.IsExistKq(strYear, strMonth))
            {
                JSUtility.Alert(this, "该月考勤信息已经存在");
                return;
            }
            DataTable dt = fromKingdeeBiz.GetListsFromKq(strYear, strMonth);
            if (dt.Rows.Count > 0)
            {
                if (fromKingdeeBiz.BulkInsert(dt))                
                    JSUtility.Alert(this, "提取该月考勤信息成功");
                else
                    JSUtility.Alert(this, "提取该月考勤信息失败");
            }
            else
                JSUtility.Alert(this, "无该月考勤信息");
        }
        //删除某年某月的考勤数据 (一般再次提取的时候，执行此操作)
        protected void btnDelKq_Click(object sender, EventArgs e)
        {
            string strYear = ddlYear.SelectedItem.Text;
            string strMonth = ddlMonth.SelectedItem.Text;
            if (fromKingdeeBiz.DeleteKq(strYear, strMonth))
                JSUtility.Alert(this, "删除该月考勤信息成功");
            else
                JSUtility.Alert(this, "删除该月考勤信息失败");
        }

        protected void btnSameEmp_Click(object sender, EventArgs e)
        {
            //前提  必须手工先同步 职位，在职状态、部门 
            DataTable dt = fromKingdeeBiz.GetNewEmpList();
            if (dt.Rows.Count > 0)
            {
                if (fromKingdeeBiz.BulkOut(dt))
                {
                    if (fromKingdeeBiz.UpdateOut())
                    JSUtility.Alert(this, "同步员工信息成功");
                    else
                        JSUtility.Alert(this, "同步员工信息更新信息失败");
                }
                else
                    JSUtility.Alert(this, "同步员工信息拷贝到考勤服务器失败");
            }
            else
                JSUtility.Alert(this, "没有需要同步的雇员资料");
        }
    }
}